{include file="common/header"}
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">*</font>短链接code</label>
                <div class="layui-input-block">
                    <input type="text" name="link_code" class="layui-input" lay-verify="required"
                           value="{$data['link_code']}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">*</font>长链接地址</label>
                <div class="layui-input-block">
                    <input type="text" name="link_url" class="layui-input" lay-verify="required"
                           value="{$data['link_url']}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">*</font>过期时间</label>
                <div class="layui-input-block">
                    <input type="text" name="expire_time" id="expire_time" class="layui-input" lay-verify="required"
                           value="{$data['expire_time']}">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <input type="hidden" name="__token__" id="__token__" value="{:token()}"/>
            <input type="hidden" name="link_id" value="{$data['link_id']??''}">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'jquery', 'common', 'laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let laydate = layui.laydate;

        laydate.render({
            elem: '#expire_time',
        });

        form.on('submit(save)', function (data) {
            $.ajax({
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dict-table");
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 1000}, function () {
                            common.getToken("{$Request.root}");
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>